<%@page language="java" contentType="application/json;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="hyl.core.db.*,hyl.core.MyFun"%>
<%@page import="hyl.core.info.Content,com.servlet.My"%>
<%@page import="hyl.ext.base.MySession"%>
<%@page import="hyl.ext.web.ms.*"%>
<%@ page
	import="java.util.List,java.util.Map,java.net.HttpURLConnection"%>
<%@page import="com.servlet.M2,hyl.core.net.MyHttp"%>
<%
MySession tk = My.getSession(request, response);
String auser = request.getParameter("auser");
String bappid = request.getParameter("bappid");
String buser = request.getParameter("buser");
String bpass = request.getParameter("bpass");
Content ct = new Content();

////////////////////////////////dao//////////////////////////////////

//先验证 该记录是否已经 存在如果存在不新增

TMsA ma = My.getMsA();
Map<String, Object> usera = ma.getUser(auser);
ABOpen open = ma.getABOpen1((int) usera.get("id"), bappid);
//MyFun.print()
if (open != null) {
	ct.setCode(0, "用户关系已经存在");
	out.print(ct.toJsonString());
	return;
}
BInfo bi = ma.getBInfo(bappid);
String userb = "";
String mw = bi.aes加密64(MyFun.join2(",", buser, bpass));
String urlb = MyFun.join(bi.getBURL(), "/ssob/checkbuser?mw=", mw);
//MyFun.print(bi.getBURL()," ::  ",urlb);
HttpURLConnection conn = MyHttp.sendGet(urlb);
String result = MyHttp.getResult(conn);

if (!MyFun.isEmpty(result) && result.charAt(0) == 'Y') {
	//MyFun.print(result.substring(1));
	userb = bi.aes解密64(result.substring(1));
} else
	userb = null;
//ma.req向B提问(TMsA."验证登录");
String[] userbs = userb.split(",");
if (null == userb) {
	ct.setCode(0, "用户密码错误");
} else {
	open = new ABOpen();
	open.openid = MyFun.getUUID();
	open.appB = bappid;
	open.uidA = MyFun.obj2Int(usera.get("id"));
	open.unameA = MyFun.obj2Str(usera.get("uname"));
	open.uidB = MyFun.str2int(userbs[0]);
	open.unameB = userbs[1];
	ma.insertABOpen(open);
	ct.setCode(1, "关系建立成功");
}

//ma.getBInfo(bappid).

out.print(ct.toJsonString());
%>